﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 新增编码表 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "SysCodeRule",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    CodeType = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    Prefix = table.Column<string>(type: "nvarchar(16)", maxLength: 16, nullable: true),
                    DateFormat = table.Column<string>(type: "nvarchar(16)", maxLength: 16, nullable: true),
                    SerialLength = table.Column<int>(type: "int", nullable: false),
                    Suffix = table.Column<string>(type: "nvarchar(16)", maxLength: 16, nullable: true),
                    ResetRule = table.Column<int>(type: "int", nullable: false),
                    CurrentSerial = table.Column<int>(type: "int", nullable: false),
                    LastGenerateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastResetTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    IsEnabled = table.Column<bool>(type: "bit", nullable: false),
                    Sort = table.Column<int>(type: "int", nullable: false),
                    Remark = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                    TenantCode = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysCodeRule", x => x.ID);
                });

            migrationBuilder.CreateTable(
                name: "SysCodeHistory",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CodeRuleId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    GeneratedCode = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    BusinessId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    BusinessType = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    SerialNumber = table.Column<int>(type: "int", nullable: false),
                    GenerateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Operator = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Remark = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                    TenantCode = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysCodeHistory", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysCodeHistory_SysCodeRule_CodeRuleId",
                        column: x => x.CodeRuleId,
                        principalTable: "SysCodeRule",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysCodeHistory_CodeRuleId",
                table: "SysCodeHistory",
                column: "CodeRuleId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SysCodeHistory");

            migrationBuilder.DropTable(
                name: "SysCodeRule");
        }
    }
}
